//
//  Item.m
//  yuimall_Iphone
//
//  Created by yuike6 yuike6 on 12-4-16.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "Item.h"
#import "header.h"

@implementation Item
@synthesize detail_url;
@synthesize num_iid;

@synthesize title;
@synthesize nick;

@synthesize type;
@synthesize desc;

@synthesize props_name;
@synthesize created;

@synthesize is_lightning_consignment;
@synthesize is_fenxiao;

@synthesize auction_point;
@synthesize property_alias;

@synthesize template_id;
@synthesize after_sale_id;

@synthesize is_xinpin;
@synthesize sub_stock;

@synthesize inner_shop_auction_template_id;
@synthesize outer_shop_auction_template_id;

@synthesize cid;
@synthesize seller_cids;

@synthesize props;
@synthesize input_pids;

@synthesize input_str;
@synthesize pic_url;

@synthesize num;
@synthesize valid_thru;

@synthesize list_time;
@synthesize delist_time;

@synthesize stuff_status;
@synthesize location;

@synthesize price;
@synthesize post_fee;

@synthesize express_fee;
@synthesize ems_fee;

@synthesize has_discount;
@synthesize freight_payer;

@synthesize has_invoice;
@synthesize has_warranty;

@synthesize has_showcase;
@synthesize modified;

@synthesize increment;
@synthesize approve_status;

@synthesize postage_id;
@synthesize product_id;

@synthesize item_imgs;
@synthesize prop_imgs;

@synthesize outer_id;
@synthesize is_virtual;

@synthesize is_taobao;
@synthesize is_ex;

@synthesize is_timing;

@synthesize videos;
@synthesize is_3D;

@synthesize one_station;
@synthesize second_kill;

@synthesize auto_fill;
@synthesize violation;


@synthesize wap_desc;
@synthesize wap_detail_url;

@synthesize cod_postage_id;
@synthesize sell_promise;


-(void)dealloc
{
    YRelease(detail_url)
    YRelease(num_iid)
    
    YRelease(title)
    YRelease(nick)
    
    YRelease(type)
    YRelease(desc)
    
    YRelease(props_name)
    YRelease(created)
    
    //
    YRelease(is_fenxiao);
    
    YRelease(auction_point)
    YRelease(property_alias)
    
    YRelease(template_id)
    YRelease(after_sale_id);
    
    YRelease(template_id)
    YRelease(after_sale_id);
    
    //
    YRelease(sub_stock);
    
    YRelease(inner_shop_auction_template_id)
    YRelease(outer_shop_auction_template_id)
    
    
    YRelease(cid)
    YRelease(seller_cids)
    
    YRelease(props)
    YRelease(input_pids)
    
    YRelease(input_str)
    YRelease(pic_url)
    
    YRelease(num)
    YRelease(valid_thru)
    
    YRelease(list_time)
    YRelease(delist_time)
    
    YRelease(stuff_status)
    YRelease(location)
    
    YRelease(price)
    YRelease(post_fee)
    
    YRelease(express_fee)
    YRelease(ems_fee)
    
    //
    YRelease(freight_payer)
    
    //
    //
    
    //
    YRelease(modified)
    
    YRelease(increment)
    //
    
    YRelease(postage_id)
    YRelease(product_id)
    
    YRelease(item_imgs);
    YRelease(prop_imgs);
    
    YRelease(outer_id)
    //
    
    //
    //
    
    //
    YRelease(videos);
    YRelease(second_kill)
    
    YRelease(auto_fill)
    //
    
    YRelease(wap_desc)
    YRelease(wap_detail_url)
    
    YRelease(cod_postage_id)
    //
    
    
    
    [super dealloc];
}

-(void) privateInit
{
    self.detail_url = [self.xmlTree valueAtPath:@"item/detail_url"];
    self.num_iid = [self.xmlTree valueAtPath:@"item/num_iid"];
    
    self.title = [self.xmlTree valueAtPath:@"item/title"];
    self.nick = [self.xmlTree valueAtPath:@"item/nick"];
    
    self.type = [self.xmlTree valueAtPath:@"item/type"];
    self.desc = [self.xmlTree valueAtPath:@"item/desc"];
    
    self.props_name = [self.xmlTree valueAtPath:@"item/props_name"];
    self.created = [NSDate string2date:[self.xmlTree valueAtPath:@"item/created"]];
    
    self.is_lightning_consignment = [[self.xmlTree valueAtPath:@"item/is_lightning_consignment"] boolValue];        
    self.is_fenxiao = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/is_fenxiao"] doubleValue]];
    
    self.auction_point = [self.xmlTree valueAtPath:@"item/auction_point"];
    self.property_alias = [self.xmlTree valueAtPath:@"item/property_alias"];
    
    self.template_id = [self.xmlTree valueAtPath:@"item/template_id"];
    self.after_sale_id = [self.xmlTree valueAtPath:@"item/after_sale_id"];
    
    self.is_xinpin = [[self.xmlTree valueAtPath:@"item/is_xinpin"] boolValue];
   
    self.sub_stock = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/sub_stock"] doubleValue]];
    
    self.inner_shop_auction_template_id = [self.xmlTree valueAtPath:@"item/inner_shop_auction_template_id"];
    self.outer_shop_auction_template_id = [self.xmlTree valueAtPath:@"item/outer_shop_auction_template_id"];
    
    self.cid =  [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/cid"] doubleValue]];
    self.seller_cids = [self.xmlTree valueAtPath:@"item/seller_cids"];
    
    self.props = [self.xmlTree valueAtPath:@"item/props"];
    self.input_pids = [self.xmlTree valueAtPath:@"item/input_pids"];
    
    self.input_str = [self.xmlTree valueAtPath:@"item/input_str"];
    self.pic_url = [self.xmlTree valueAtPath:@"item/pic_url"];
    
    self.num =  [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/num"] doubleValue]];
    self.valid_thru = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/valid_thru"] doubleValue] ];
    
    self.list_time = [NSDate string2date:[self.xmlTree valueAtPath:@"item/list_time"]];
    self.delist_time = [NSDate string2date:[self.xmlTree valueAtPath:@"item/delist_time"]];
    self.stuff_status = [self.xmlTree valueAtPath:@"item/stuff_status"];
    
    Location * tmp_location = [[Location alloc] initWithXmlTree:[self.xmlTree parsedTreeAtPath:@"item/location"]];
    self.location = tmp_location;
    YRelease(tmp_location);
    
    Price * tmp_price = [[Price alloc] initWithXmlTree:[self.xmlTree parsedTreeAtPath:@"item/price"]];
    self.price = tmp_price;
    YRelease(tmp_price);
    
    Price * tmp_post_fee = [[Price alloc] initWithXmlTree:[self.xmlTree parsedTreeAtPath:@"item/post_fee"]];
    self.post_fee = tmp_post_fee;
    YRelease(tmp_post_fee);
    
    Price * tmp_express_fee = [[Price alloc] initWithXmlTree:[self.xmlTree parsedTreeAtPath:@"item/express_fee"]];
    self.express_fee = tmp_express_fee;
    YRelease(tmp_express_fee);
    
    Price * tmp_ems_fee = [[Price alloc]initWithXmlTree:[self.xmlTree parsedTreeAtPath:@"item/ems_fee"]];
    self.ems_fee = tmp_ems_fee;
    YRelease(tmp_ems_fee);
    
    self.has_discount = [[self.xmlTree valueAtPath:@"item/has_discount"] boolValue];
    self.freight_payer = [self.xmlTree valueAtPath:@"item/freight_payer"];
    
    self.has_invoice = [[self.xmlTree valueAtPath:@"item/has_invoice"] boolValue];
    self.has_warranty = [[self.xmlTree valueAtPath:@"item/has_warranty"] boolValue];
    
    self.has_showcase = [[self.xmlTree valueAtPath:@"item/has_showcase"] boolValue];
    self.modified = [NSDate string2date:[self.xmlTree valueAtPath:@"item/modified"]];
    
    self.increment = [self.xmlTree valueAtPath:@"item/increment"];
    self.approve_status = [[self.xmlTree valueAtPath:@"item/approve_status"] boolValue];
    
    self.postage_id = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/postage_id"] doubleValue]];
    self.product_id = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/product_id"]doubleValue]];
    
    NSMutableArray * tmp_item_imgs = [[NSMutableArray alloc] init];
    for (XMLParsedTree * subTree in [self.xmlTree childrenTreeAtPath:@"item/item_imgs" nodeName:@"item_img"]) {
        ItemImg * itemImage = [[ItemImg alloc] initWithXmlTree:subTree];
        [tmp_item_imgs addObject:itemImage];
        YRelease(itemImage)
    }    
    self.item_imgs = tmp_item_imgs;
    YRelease(tmp_item_imgs);
    
    NSMutableArray * tmp_prop_imgs = [[NSMutableArray alloc] init];
    for (XMLParsedTree * subTree in [self.xmlTree childrenTreeAtPath:@"item/prop_imgs" nodeName:@"prop_img"]) {
        PropImg * propImg = [[PropImg alloc] initWithXmlTree:subTree];
        [tmp_prop_imgs addObject:propImg];
        YRelease(propImg);
    }    
    self.prop_imgs = tmp_prop_imgs;
    YRelease(tmp_prop_imgs);
    
    
    self.outer_id = [self.xmlTree valueAtPath:@"item/outer_id"];
    
    self.is_virtual = [[self.xmlTree valueAtPath:@"item/is_virtual"] boolValue];
    self.is_taobao = [[self.xmlTree valueAtPath:@"item/is_taobao"] boolValue];
    
    self.is_ex = [[self.xmlTree valueAtPath:@"item/is_ex"] boolValue];
    self.is_timing = [[self.xmlTree valueAtPath:@"item/is_timing"] boolValue];
    
    // video list  to do...
    self.is_3D = [[self.xmlTree valueAtPath:@"item/is_3D"] boolValue];
    
    self.one_station = [[self.xmlTree valueAtPath:@"item/one_station"] boolValue];
    self.second_kill = [self.xmlTree valueAtPath:@"item/second_kill"];
    
    self.auto_fill = [self.xmlTree valueAtPath:@"item/auto_fill"];
    self.violation = [[self.xmlTree valueAtPath:@"item/violation"] boolValue];
    
    self.wap_desc = [self.xmlTree valueAtPath:@"item/wap_desc"];
    self.wap_detail_url = [self.xmlTree valueAtPath:@"item/wap_detail_url"];
    
    self.cod_postage_id = [NSNumber numberWithDouble:[[self.xmlTree valueAtPath:@"item/cod_postage_id"] doubleValue]];
    self.sell_promise = [[self.xmlTree valueAtPath:@"item/sell_promise"] boolValue];
    
}

-(id) initWithXmlTree:(XMLParsedTree *)tree
{
    self = [super initWithXmlTree:tree];
    if (self) {
        [self privateInit];
    }
    
    return self;
}


-(id) initWithXmlString:(NSString *)xmlString
{
    self = [super initWithXmlString:xmlString];
    if (self) {
        [self privateInit];
    }
    return self;
}

-(id) initWithXmlData:(NSData *)xmlData
{
    self = [super initWithXmlData:xmlData];
    if (self) {
        [self privateInit];
    }
    return self;
}

@end


















